package com.springmvc.demo.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.springmvc.demo.model.ChronicDiseaseCard;
import com.springmvc.demo.model.RefundRegistryForm;
import com.springmvc.demo.service.ChronicService;

@Controller
public class ChronicController {
	@Autowired
	ChronicService chronicServiceImpl;
	
	/*
	 * 获取慢性病证列表
	 */
	@RequestMapping("/getChronicDiseaseCard")
	@ResponseBody
	public JSONObject getChronicDiseaseCardList() {
		JSONObject jsonObject=new JSONObject();

		List<ChronicDiseaseCard> list=chronicServiceImpl.getChronicCardList();
		
		
		JSONArray jsonArray1 = (JSONArray)JSONArray.toJSON(list);
		//System.out.println(f.getHost_name());
		jsonObject.put("data", jsonArray1);
		return jsonObject;
		
	}
	
	/*
	 * 添加慢性病证信息
	 */
	@PostMapping("/addDiseaseCard")
	@ResponseBody
	public String addChronicDiseaseCard(ChronicDiseaseCard cdc) {
		String chronicDiseaseCardNo=cdc.getPersonId()+"2018";
		cdc.setChronicDiseaseCardNo(chronicDiseaseCardNo);
		System.out.println(cdc.getPersonId());
		return chronicServiceImpl.addChronicCard(cdc);
		
	}
	
	/*
	 *  获取慢性病报销信息列表
	 */
	@RequestMapping("/getChronicDiseaseRefund")
	@ResponseBody
	public JSONObject getChronicDiseaseRefundList() {
		JSONObject jsonObject=new JSONObject();

		List<?> list=chronicServiceImpl.getRefundList();
		
		
		JSONArray jsonArray1 = (JSONArray)JSONArray.toJSON(list);
		//System.out.println(f.getHost_name());
		jsonObject.put("data", jsonArray1);
		return jsonObject;
		
	}
	
	
	/*
	 * 慢性病报销
	 */	
	@PostMapping("/chronicDiseaseRefund")
	@ResponseBody
	public String chronicDiseaseRefund(RefundRegistryForm rf) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        Date date = new Date();
        String refundFormNo=sdf.format(date);
        refundFormNo+=date.getTime();
        
        rf.setRefundFormNo(refundFormNo);
		return chronicServiceImpl.refundCost(rf);
		
	}
	
}
